import { Component } from '@angular/core';
import * as io from 'socket.io-client';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less'],
})
export class AppComponent {
  content = ``;
  ngOnInit(): void {
    const socket = io('ws://127.0.0.1:7001');
    // const socket = io('ws://192.168.1.6:7001');
    socket.on('connect', (data) => {
      console.log('connect');
    });
    socket.on('socketId', (data) => {
      localStorage.setItem('socketId', data);
    });
    socket.on('msg', (data: string) => {
      this.showCon = true;
      this.content += data + '<br/>';
      document.getElementById('contentLogger').scrollTop =
        document.getElementById('contentLogger').scrollHeight;
      if (data.includes('exit')) {
        this.showCon = false;
        this.content = '';
      }
    });
  }
  showCon = false;
}
